#!/bin/bash

. $OPENARS_HOME/common/debug.h
. $OPENARS_HOME/common/functions.h

user=$USER_ARS
[ -z "$user" ] && user=$LOGNAME

>$OUTFILE

srvlist=`get_hosts --os=Unix --control=YES`
INF "count hosts: `echo $srvlist | wc -w`"

    for server in $srvlist ; do
	(
	result=""
	SSH $user@$server "df -k| grep -v \":\"|sed '1d'|awk '{print \$1,\":\",\$2,\":\",\$3,\":\",\$5,\":\",\$6}'|grep -v \"/etc\"|grep -v \"cdrom\"|grep -v \"dmpfs\"|grep -v \"fd\"|grep -v \"swap\"|grep -v \"system\"|grep -v \"lib\"|grep -v \"proc\" |grep -v \"/devices\" |grep -v \"/mnt/\"" result
	ex_code="$?"
	if [ "$ex_code" -eq 255 ]; then
	    echo "not connected:0:0:0%:null" >> $TEMPDIR/$server.df
	    continue
	fi
	echo "$result" | sed 's/ //g' >> $TEMPDIR/$server.df
	) &
    done

WAIT 180

cd $TEMPDIR

    srvlist=`ls *.df | awk -F. '{print $1}'`
    for server in $srvlist
    do
	awk '{print "'$server'"  ":" $0}' $server.df >> $OUTFILE
    done

echo "load data infile \"$OUTFILE\" truncate into table FS_tmp fields terminated by \":\" ( host,storage,fs_size,used,capacity,mpoint )" > $OUTDIR/df.load.ctl

if [ -z "$CONNECT_ARS" ]; then
    ERR "not defined CONNECT_ARS environment for Oracle connect. exit."
    exit 1;
fi

$ORACLE_HOME/bin/sqlldr -userid=$CONNECT_ARS -control=$OUTDIR/df.load.ctl -log=$OUTDIR/df.load.log
$ORACLE_HOME/bin/sqlplus -s /NOLOG  <<END
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
set linesize 100
set serveroutput on
connect $CONNECT_ARS
exec FS_LOAD;
exit;
END
